package presentation.entities;

import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class DialogCreator {

    public static void showMessage(Component parent, String title, String message, int type) {
        JOptionPane.showMessageDialog(parent, message, title, type);
    }

    /**
     * Return '0' if and only if the user choose to close the program. 
     */
    public static int closeProgramDialog(JFrame frame) {
        Object[] options = {"Yes", "Cancel"};
        int userResponse = JOptionPane.showOptionDialog(frame, "Are you sure you want to close the program and disconnect from the server ?",
                "Closing The Program", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title    
        
        return userResponse;
    }

    /**
     * Return '0' if and only if the user choose to close the program. 
     */
    public static int closeProgramDialogSaveWarn(JFrame frame) {
        Object[] options = {"Yes", "Cancel"};
        int userResponse = JOptionPane.showOptionDialog(frame, "Are you sure you want to close the program and disconnect from the server ?\nMake sure you have saved your work.",
                "Closing The Program", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title    

        return userResponse;
    }

    /**
     * Return '0' if and only if the user choose to go back to login screen.
     */
    public static int backToLoginDialog(JFrame frame) {
        Object[] options = {"Yes", "Cancel"};
        int userResponse = JOptionPane.showOptionDialog(frame, "Are you sure you want to go back to login screen and disconnect from the server ?",
                "Go Back to Login Screen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title

        return userResponse;
    }

    /**
     * Return '0' if and only if the user choose to go back to login screen.
     */
    public static int backToLoginDialogSaveWarn(JFrame frame) {
        Object[] options = {"Yes", "Cancel"};
        int userResponse = JOptionPane.showOptionDialog(frame, "Are you sure you want to go back to login screen and disconnect from the server ?\nMake sure you have saved your work.",
                "Go Back to Login Screen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title

        return userResponse;
    }

    /**
     * Return '0' if and only if the user choose to go back to previous screen.
     */
    public static int backToListsScreenDialog(JFrame frame) {
        Object[] options = {"Yes", "Cancel"};
        int userResponse = JOptionPane.showOptionDialog(frame, "Are you sure you want to go back to the previous screen ?\nMake sure you have saved your work.",
                "Go Back to Previous Screen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title

        return userResponse;
    }

    /**
     * Return '0' if and only if the user confirm the deletion.
     */
    public static int deleteExistFileDialog(JFrame frame) {
        Object[] options = {"Yes", "Cancel"};
        int userResponse = JOptionPane.showOptionDialog(frame, "Another file with the same name already exist and will be deleted.\nDo you want to continue ?",
                "Another File With the Same Name Already Exist", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title

        return userResponse;
    }
    
   /**
    * Return '0' if and only if the user confirm the deletion.
    */
    public static int deleteFilterDialog(JFrame frame) {
        Object[] options = {"Yes", "Cancel"};
        int userResponse = JOptionPane.showOptionDialog(frame, "Are you sure you want to delete the selected filter ?\n"
                + "All its child filters will also be deleted.",
                "Delete Filter", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[1]); //default button title

        return userResponse;
    }
}
